<template>
  <div id="app">
    <!-- 需要缓存的界面 -->
    <transition :name="nameTransition">
      <keep-alive :include="CACHE">
        <router-view />
      </keep-alive>
    </transition>
  </div>
</template>
<script>
import { CACHE } from '@/js/setting.js';
export default {
  name: 'app',
  watch: {
    $route(to, from) {
      if (Object.prototype.toString.call(to.meta.index) != '[object Undefined]' && Object.prototype.toString.call(from.meta.index) != '[object Undefined]') {
        if (to.meta.index > from.meta.index) {
          // 父-子
          this.nameTransition = 'slide-left';
        } else {
          this.nameTransition = 'slide-right';
        }
      } else {
        this.nameTransition = '';
      }
    },
  },
  data() {
    return {
      nameTransition: '',
      CACHE,
    };
  },
  methods: {},
  created() {},
};
</script>

<style>
body {
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin: 0;
  letter-spacing: 0.034em;
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;
}
[v-cloak] {
  display: none;
}
@import url('./css/index.css');

.slide-left-leave-active,
.slide-left-enter-active,
.slide-right-leave-active,
.slide-right-enter-active {
  transition: all 0.5s;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.slide-right-leave,
/* 父页面 */
.slide-right-enter-to {
  transform: translateX(0);
}
.slide-right-leave-to {
  transform: translateX(100%);
}

/* 父界面 */
.slide-right-enter {
  transform: translateX(-100%);
}
/* 父页面 */
.slide-left-leave,
/* 子界面 */
.slide-left-enter-to {
  transform: translateX(0);
}
.slide-left-leave-to {
  transform: translateX(-100%);
}
/* 子界面 */
.slide-left-enter {
  transform: translateX(100%);
}
</style>
